package com.zwr.sheller.shop.service.impl;

import com.zwr.sheller.core.common.WDMBusinessException;
import com.zwr.sheller.core.common.WDMExceptionCode;
import com.zwr.sheller.core.pojo.OriginOrder;
import com.zwr.sheller.core.service.impl.BaseServiceImpl;
import com.zwr.sheller.shop.mapper.OriginOrderMapper;
import com.zwr.sheller.shop.service.OriginOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wdm
 */
@Service("originOrderService")
public class OriginOrderServiceImpl extends BaseServiceImpl<OriginOrder> implements OriginOrderService {
    @Autowired(required = false)
    private OriginOrderMapper originOrderMapper;


    @Override
    public List<Map<String, Object>> selectOrderByDateAndStatus(Integer status, String date, String orderNum, String goodsName, Integer page) throws WDMBusinessException {
        List<Map<String, Object>> maps = originOrderMapper.selectOrderByDateAndStatus(status, date, orderNum, goodsName, (page - 1) * 3);
        if (maps.size()<0){
            throw new WDMBusinessException(WDMExceptionCode.SELECT_FAILED);
        }
        return maps;
    }

    @Override
    public Map<String, Object> selectOrderDetailByOrderId(Long orderId) throws WDMBusinessException {
        OriginOrder originOrder = originOrderMapper.selectOriginOrderDetailById(orderId);
        List<Map<String, Object>> maps = originOrderMapper.selectGoodsDetailByOrderId(orderId);
        Map<String, Object> map = originOrderMapper.selectAdressFromOrder(orderId);
        if (originOrder!= null && maps.size() >= 1 && map.size() > 0){
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("goodsDetail",maps);
            resultMap.put("orderDetail",originOrder);
            resultMap.put("addressDetail",map);
            return resultMap;
        }
        throw  new WDMBusinessException(WDMExceptionCode.SELECT_FAILED);
    }

    @Override
    public List<Map<String, Object>> queryOrderToBeReceived(String date, Integer deliveryMethod) {
        List<Map<String, Object>> maps = originOrderMapper.queryOrderToBeReceived(date, deliveryMethod);
        return maps;
    }

    @Override
    public List<Map<String, Object>> querySelfWithdrawalOrder(String date, String orderNum, String goodsName) {
        List<Map<String, Object>> maps = originOrderMapper.querySelfWithdrawalOrder(date, orderNum, goodsName);


        return maps;
    }

    @Override
    public List<Map<String, Object>> queryRefoundOrder(Integer refundStatus, String date, String orderNum, String goodsName) {
        List<Map<String, Object>> maps = originOrderMapper.queryRefoundOrder(refundStatus, date, orderNum, goodsName);
        return maps;
    }
}
